package com.ruoyi.web.controller.psi;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.Category;
import com.ruoyi.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * lhp
 * 2023/8/30
 */
@RestController
@RequestMapping("/category")
public class CategoryController extends BaseController {
    @Autowired
    private CategoryService categoryService;

    @Log(title = "查询分类列表", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('psi:category:query')")
    @RequestMapping("/list")
    public TableDataInfo list(){
        startPage();
        List<Category> list = categoryService.getList();
        return getDataTable(list);
    }

    @Log(title = "增加类别", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('psi:category:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Category category){
        AjaxResult ajaxResult = categoryService.add(category);
        return ajaxResult;
    }

    @Log(title = "删除商品信息", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('psi:category:del')")
    @RequestMapping("/delList")
    public AjaxResult delList(@RequestBody List<String> ids){
        AjaxResult ajaxResult = categoryService.delList(ids);
        return ajaxResult;
    }

    @Log(title = "获取商品编号", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('psi:category:query')")
    @RequestMapping("/getNo/{id}")
    public String getNo(@PathVariable String id){
        String no = categoryService.getNo(id);
        return no;
    }

}
